#pragma once

/**
 * This class handle http curl comunication with Viafirma server.
*/
#include "curl\curl.h"

#include <string>

namespace netDefaults
{
  const int CURL_DEFAULT_BUFFSIZE = 10024;
  const std::string CURL_COLON = ":";
  const char CURL_EOS = '\0';
};

class netUtil
{
public:
	netUtil();
	~netUtil();
    void clearCurlCallbackBuffers();
    void prepareCurlProxy();
    void prepareCurlCallback();
    void prepareStandardParams();
    bool performGet( const std::string& getUrl );
	bool performPost( const std::string& getUrl ,const char * postfields);

	/* cURL proxy get/set APIs */
    std::string& getProxyServerIp();
    std::string& getProxyServerPort();
    std::string& getProxyUserName();
    std::string& getProxyPassword();
    void setProxyServerIp( std::string& proxyServerIp );
    void setProxyServerPort( std::string& proxyServerPort );
    void setProxyUserName( std::string& proxyUserName );
    void setProxyPassword( std::string& proxyPassword );


	char * encode(const char * encode);
	/* cURL APIs */
    bool isCurlInit();
    void getLastWebResponse( std::string& outWebResp );
    void getLastCurlError( std::string& outErrResp );

private:
    /* cURL data */
    CURL* m_curlHandle;
	char m_errorBuffer[netDefaults::CURL_DEFAULT_BUFFSIZE];
    std::string m_callbackData;

	struct curl_httppost *post;
	struct curl_httppost *last;

    
    /* cURL flags */
    bool m_curlProxyParamsSet;
    bool m_curlCallbackParamsSet;
    
    /* cURL proxy data */
    std::string m_proxyServerIp;
    std::string m_proxyServerPort;
    std::string m_proxyUserName;
    std::string m_proxyPassword;

	  /* Internal cURL methods */
    int saveLastWebResponse( char*& data, size_t size );
    static int curlCallback( char* data, size_t size, size_t nmemb, netUtil* pYelpCurlObj );
};

/* Private utility functions */
void utilMakeCurlParams( std::string& outStr, std::string& inParam1, std::string& inParam2 );

